﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class BalanceCenter_Information : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            int TypeID = Shove._Convert.StrToInt(Shove._Web.Utility.GetRequest("ID"), 1);

            tbTypeID.Text = TypeID.ToString();

            if (TypeID == 1)
            {
                LabTitle.Text = "培训信息";
            }
            else if (TypeID == 2)
            {
                LabTitle.Text = "新闻信息";
            }
            else if (TypeID == 3)
            {
                LabTitle.Text = "活动信息";
            }
            else if (TypeID == 5)
            {
                LabTitle.Text = "其他信息";
            }

            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        isAtFramePageLogin = true;                              //是框架页

        base.OnLoad(e);
    }

    #endregion

    private void BindData()
    {
        PagedDataSource Pds = new PagedDataSource();

        DataTable dt = new DAL.Tables.tbl_Information().Open("", "isShow = 1 and Type = " + tbTypeID.Text, "[DateTime] desc");

        if (dt == null)
        {
            PublicFunction.GoError(ErrorNumber.DataReadWrite, "数据读写错误", this.GetType().BaseType.FullName);

            return;
        }

        Pds.DataSource = dt.DefaultView;
        Pds.AllowPaging = true; //开启分页
        Pds.PageSize = 5; //分页
        PSize.Text = Pds.PageSize.ToString();

        int index = int.Parse(PageIndex.Text); //当前页数
        int PageSize = Pds.PageSize;
        int TotalRecords = Pds.DataSourceCount;
        int TotalPages = TotalRecords / PageSize;//得到总页数（总记录数除以每页的记录数） 
        int ModePages = TotalRecords % PageSize;//得到取模的余数(总记录数取模每页的记录数) 

        PageColumn.Visible = (dt.Rows.Count > 0);

        if (ModePages > 0)//如果取模数不等于0，则把总页数加1 
        {
            TotalPages += 1;
        }
        if (TotalPages == 0)
        {
            TotalPages = 1;
        }
        if (index > TotalPages)
        {
            index = TotalPages;
            PageIndex.Text = index.ToString();
        }

        MaxPage.Text = TotalPages.ToString();//显示页面上的总页数 
        TotalCount.Text = TotalRecords.ToString();//显示页面上的总记录数 
        Pds.CurrentPageIndex = index - 1;

        if (index == 1)
        {
            lnkPrev.Enabled = false;
            if (TotalPages > 1)
            {
                lnkNext.Enabled = true;
            }
            else
            {
                lnkNext.Enabled = false;
            }
        }
        else
        {
            lnkPrev.Enabled = true;

            if (index == TotalPages)
            {
                lnkNext.Enabled = false;
            }
            else
            {
                lnkNext.Enabled = true;
            }
        }

        selectPage.Items.Clear(); //清除防止累加

        for (int i = 1; i <= TotalPages; i++)
        {
            selectPage.Items.Add(i.ToString());
        }

        selectPage.Items.FindByText(index.ToString()).Selected = true; //把当前页显示在列表框的第一个
        g.DataSource = Pds;
        g.DataBind();
    }

    protected void lnkPrev_Click(object sender, EventArgs e)
    {
        int index = int.Parse(PageIndex.Text);
        index--;
        PageIndex.Text = index.ToString();
        BindData();
    }

    protected void lnkNext_Click(object sender, EventArgs e)
    {
        int index = int.Parse(PageIndex.Text);
        index++;
        PageIndex.Text = index.ToString();
        BindData();
    }

    protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        PageIndex.Text = selectPage.SelectedValue;
        BindData();
    }

}
